package m202405.d14;

import java.util.Stack;

/**
 * @@author: 爱做梦的锤子
 * @date: 2024/5/14 16:28
 */
public class Q155 {
    public static class MinStack {

        Stack<Node> stack;

        public MinStack() {
            this.stack = new Stack<>();
        }

        public void push(int val) {
            if (stack.isEmpty()) {
                stack.push(new Node(val, val));
            } else {
                stack.push(new Node(val, Math.min(stack.peek().min, val)));
            }
        }

        public void pop() {
            stack.pop();
        }

        public int top() {
            return stack.peek().val;
        }

        public int getMin() {
            return stack.peek().min;
        }

        private static class Node {
            int val;
            int min;

            public Node(int val, int min) {
                this.val = val;
                this.min = min;
            }
        }
    }
}
